from django.contrib import admin
from app.models import Project, ProjectMember, Contact, Test, Tag

admin.site.site_header = '用例管理'
admin.site.site_title = '测试平台'

# ----------------------------------------------------------------

# Register your models here.

from app.models import Project, ProjectDynamic, ProjectMember
from django.contrib import admin
from django.utils.text import capfirst
from collections import OrderedDict as SortedDict

# Register your models here.

from app.models import Project, ProjectDynamic, ProjectMember

from django.contrib import admin
from django.utils.text import capfirst
from collections import OrderedDict as SortedDict


# def find_model_index(name):
#     count = 0
#     for model, model_admin in admin.site._registry.items():
#         if capfirst(model._meta.verbose_name_plural) == name:
#             return count
#         else:
#             count += 1
#     return count
#
#
# def index_decorator(func):
#     def inner(*args, **kwargs):
#         template_response = func(*args, **kwargs)
#         for app in template_response.context_data['app_list']:
#             app['models'].sort(key=lambda x: find_model_index(x['name']))
#         return template_response
#
#     return inner
#
#
# registry = SortedDict()
# registry.update(admin.site._registry)
# admin.site._registry = registry
# admin.site.index = index_decorator(admin.site.index)
# admin.site.app_index = index_decorator(admin.site.app_index)
# admin.site.site_header = '测试平台后台管理'
# admin.site.siteTitle = '后台管理'
#
# display = ()
#
#
# class ReadOnlyModelAdmin(admin.ModelAdmin):
#     actions = None
#
#     def get_readonly_fields(self, request, obj=None):
#         return self.fields or [f.name for f in self.model._meta.fields]
#
#     def has_add_permission(self, request):
#         return False
#
#     # Allow viewing objects but not actually changing them
#     def has_change_permission(self, request, obj=None):
#         if request.method not in ('GET', 'HEAD'):
#             return True
#         return super(ReadOnlyModelAdmin, self).has_change_permission(request, obj)
#
#     def has_delete_permission(self, request, obj=None):
#         return False
#
#
# class MemberInProject(admin.TabularInline):
#     model = ProjectMember
#
#
# class ProjectForm(admin.ModelAdmin):
#     inlines = [MemberInProject]
#     search_fields = ('name', 'type')
#     list_display = ('id', 'name', 'version', 'type', 'status', 'LastUpdateTime', 'createTime')
#     list_display_links = ('id', 'name',)
#     list_filter = ('status', 'type')
#     list_per_page = 20
#     ordering = ('id',)
#     fieldsets = ([
#                      '项目', {
#             'fields': ('name', 'version', 'type', 'description', 'status')
#         }],
#     )
#
#
# admin.site.register(Project, ProjectForm)
#
#
# class ProjectMemberForm(admin.ModelAdmin):
#     search_fields = ('user', 'project')
#     list_display = ('id', 'permission_type', 'project', 'user')
#     list_display_links = ('permission_type', 'project')
#     list_filter = ('id', 'permission_type', 'project', 'user')
#     list_per_page = 20
#     ordering = ('id',)
#     fieldsets = ([
#                      '项目成员', {
#             'fields': ('permission_type', 'project', 'user')
#         }],
#     )
#
#
# admin.site.register(ProjectMember, ProjectMemberForm)


# class ProjectDynamicForm(ReadOnlyModelAdmin):
#     search_fields = ('operationObject', 'user')
#     list_display = ('id', 'project', 'time', 'type', 'operationObject', 'description', 'user')
#     list_display_links = ('id', 'project', 'time')
#     list_filter = ('project', 'type')
#     list_per_page = 20
#     ordering = ('-id',)
#
#
# admin.site.register(ProjectDynamic, ProjectDynamicForm)
# 添加的时候显示年龄
# class ContactAdmin(admin.ModelAdmin):
#     # fields = ('name', 'email')
#     fieldsets = (
#         ['Main', {
#             'fields': ('name', 'email'),
#         }],
#         ['Advance', {
#             'classes': ('collapse',),  # CSS
#             'fields': ('age',),
#         }]
#     )
#
#
# admin.site.register(Contact, ContactAdmin)
# admin.site.register([Test, Tag])


# Register your models here.

# 选择外部数据库字段
# class TagInline(admin.TabularInline):
#     model = Tag
#
#
# class ContactAdmin(admin.ModelAdmin):
#     inlines = [TagInline]  # Inline
#     fieldsets = (
#         ['列表', {
#             'fields': ('name', 'email'),
#         }],
#         ['下拉加载', {
#             'classes': ('collapse',),
#             'fields': ('age',),
#         }]
#
#     )
#
#
# admin.site.register(Contact, ContactAdmin)
# admin.site.register([Test])




# Register your models here.
# class TagInline(admin.TabularInline):
# #     model = Tag
# #
# #
# # class ContactAdmin(admin.ModelAdmin):
# #     list_display = ('name', 'age', 'email')  # list
# #     inlines = [TagInline]  # Inline
# #     fieldsets = (
# #         ['Main', {
# #             'fields': ('name', 'email'),
# #         }],
# #         ['Advance', {
# #             'classes': ('collapse',),
# #             'fields': ('age',),
# #         }]
# #
# #     )
# #
# #
# # admin.site.register(Contact, ContactAdmin)
# # admin.site.register([Test])




# Register your models here.
# class TagInline(admin.TabularInline):
#     model = Tag
#
#
# class ContactAdmin(admin.ModelAdmin):
#     list_display = ('name', 'age', 'email')  # list
#     search_fields = ('name',)
#     inlines = [TagInline]  # Inline
#     fieldsets = (
#         ['Main', {
#             'fields': ('name', 'email'),
#         }],
#         ['Advance', {
#             'classes': ('collapse',),
#             'fields': ('age',),
#         }]
#
#     )
#
#
# admin.site.register(Contact, ContactAdmin)
admin.site.register([Test,Tag])
admin.site.register([Project])